package com.advaita.gui;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.*;

import javax.imageio.*;
import javax.swing.*;

public class GetLicenseOrRunTrial extends JFrame implements ActionListener {
	private JButton btn;
	private JButton getLicenseBtn;

	public GetLicenseOrRunTrial() {
		super("Get License");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		// PJM use the screen size for the default ??
		setPreferredSize(new Dimension(500, 500));

		// load pathway guide image
		JPanel panel = new JPanel();
		getContentPane().add(panel);

		panel.setLayout(null);

		String path = "images/pathwayguide.jpg";

		File file = new File(path);
		BufferedImage image;
		try {
			image = ImageIO.read(file);
			JLabel label = new JLabel(new ImageIcon(image));

			// PJM use the screen size for the position
			label.setBounds(2, 1, 500, 280);
			panel.add(label);

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		btn = new JButton("Run Trial Version");

		// PJM use the screen size for the position

		btn.setFont(new Font("serif", Font.PLAIN, 16));
		btn.setBounds(150, 300, 200, 50);
		btn.addActionListener(this);
		btn.setActionCommand("Open");
		panel.add(btn);
		add(panel);

		getLicenseBtn = new JButton("Get License");
		// PJM use the screen size for the position
		getLicenseBtn.setFont(new Font("serif", Font.PLAIN, 16));
		getLicenseBtn.setBounds(150, 375, 200, 50);
		getLicenseBtn.addActionListener(this);
		getLicenseBtn.setActionCommand("Open");
		panel.add(getLicenseBtn);
		add(panel);

		pack();
		setLocationRelativeTo(null);
		setVisible(true);
	} // end of constructor GetLicenseOrRunTrial

	public void actionPerformed(ActionEvent e) {
		dispose(); // don't need the original window anymore.

		if (e.getSource() == btn) {
			JFrame frame2 = new JFrame();
			frame2.setTitle("Run Trail");
			frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			frame2.setPreferredSize(new Dimension(500, 500));

			JLabel label = new JLabel("Trial Version Running");
			label.setFont(new Font("serif", Font.PLAIN, 20));
			JPanel panel = new JPanel();
			frame2.add(panel);
			panel.add(label);
			frame2.pack();
			frame2.setLocationRelativeTo(null);
			frame2.setVisible(true);
		} else {
			GetLicense getLicense = new GetLicense();
		}

	}
} // end of class
